﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Names
{
    public partial class frmNames : Form
    {
        public frmNames()
        {
            InitializeComponent();
        }

        // Initialize strings
        string first, middle, last;
        int stringLength;

        // Get contents of name fields and format them appropriately
        private void getVars()
        {
            first = txtFirst.Text;
            first = capitalise(first);
            middle = txtMiddle.Text;
            middle = capitalise(middle);
            last = txtLast.Text;
            last = capitalise(last);
        }

        private string capitalise(string toCap)
        {
            stringLength = toCap.Length;
            string cap, remain;
            cap = toCap.Substring(0, 1).ToUpper();
            remain = toCap.Substring(1, stringLength-1).ToLower();
            toCap = cap + remain;
            return toCap;
        }

        private void btnInitials_Click(object sender, EventArgs e)
        {
            getVars();
            txtOutput.Text = first.ToUpper().Substring(0, 1) + ". " + middle.ToUpper().Substring(0, 1) + ". " + last.ToUpper().Substring(0, 1) + ".";       // Convert names entered to uppercase then strip Initials, output as text property of txtOutput.
        }

        private void btnInitSurname_Click(object sender, EventArgs e)
        {
            getVars();
            txtOutput.Text = first.ToUpper().Substring(0, 1) + ". " + middle.ToUpper().Substring(0, 1) + ". " + last;
        }

        private void btnSurnameInit_Click(object sender, EventArgs e)
        {
            getVars();
            txtOutput.Text = last + ". " + first.ToUpper().Substring(0, 1) + ". " + middle.ToUpper().Substring(0, 1) + ".";
        }

        private void btnID_Click(object sender, EventArgs e)
        {
            getVars();
            string lastLength = last.Length.ToString(); 
            first = endNom(first);
            middle = endNom(middle);
            last = endNom(last);
            txtOutput.Text = first.ToUpper() + middle.ToUpper() + last.ToUpper() + lastLength;
        }

        // Get value of last character of name entered
        private string endNom(string name)
        {
            int nomLength = name.Length;
            string nomTemp = name.Substring(nomLength - 1, 1);
            return nomTemp;
        }
    }
}
